﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ESpace
{
    class EGrid1 : Panel
    {
        public class FldSize
        {
            int[] val;
            public FldSize(int size)
            {
                val = new int[size];
            }
            public int this[int ind]
            {
                get{return val[ind];}
                set{val[ind] = value;}
            }
            public int Length
            {
                get{return val.Length;}
                set{Array.Resize<int>(ref val,value);}
            }
        }

        public Label[,] lbl = new Label[3,3];
        public int W { get { return clW.Length; } }
        public int H { get { return clH.Length; } }

        FldSize clW;
        FldSize clH;

        public FldSize ColWidth
        {
            get { return clW; }
            set { ColWidth = value; ReSetPosLbl(); }
        }


        public void SetColWidth(int indCol, int newSize)
        {
            clW[indCol] = newSize;
            ReSetPosLbl();
        }

        public void SetColWidth(int[] newSize)
        {
            for (int i = 0; i < clW.Length; i++)
                clW[i] = newSize[i];
            ReSetPosLbl();
        }

        public void SetRowHeight(int indRow, int newSize)
        {
            clH[indRow] = newSize;
            ReSetPosLbl();
        }

        public void SetRowHeight(int[] newSize)
        {
            for (int i = 0; i < clH.Length; i++)
                clH[i] = newSize[i];
            ReSetPosLbl();
        }

        void ReSetPosLbl()
        {
            int x = 3;
            int y = 3;
            for (int i = 0; i < W; i++)
            {
                y = 3;
                for (int j = 0; j < H; j++)
                {
                    lbl[i, j].Size = new Size(clW[i] + 1, clH[j] + 1);
                    lbl[i, j].Location = new Point(x, y);
                    y += clH[j];
                }
                x += clW[i];
            }
            Size = new Size(x + 6, y + 6);
        }

        public EGrid1()
        {
            int W = 3;
            int H = 3;
            lbl = new Label[W, H];
            clW = new FldSize(W);
            clH = new FldSize(H);
            BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            for (int i = 0; i < W; i++)
            {
                clW[i] = 30;
                for (int j = 0; j < H; j++)
                {
                    clH[j] = 15;
                    lbl[i, j] = new Label();
                    lbl[i, j].AutoSize = false;
                    lbl[i, j].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    lbl[i, j].Text = "";
                    Controls.Add(lbl[i, j]);
                }
            }
            ReSetPosLbl();
        }
    }
}
